home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8241 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: shell.portal.com!not-for-mail
  2. From: clare@shell.portal.com (Clare Chu)
  3. Newsgroups: comp.lang.c++
  4. Subject: Virtual Constructors (how to implement)?
  5. Date: 15 Feb 1996 17:12:14 -0800
  6. Organization: Portal Communications Company -- 408/973-9111 (voice) 408/973-8091 (data)
  7. Message-ID: <4g0lle$nmq@jobe.shell.portal.com>
  8. NNTP-Posting-Host: jobe.shell.portal.com
  9.  
  10.  
  11. I have an abstract base class Packet.  Inherited from Packet
  12. are specific packets like LoginPacket, AuditPacket, etc.
  13.  
  14. What I need is to read a socket (stream), and then construct
  15. the packet of the right kind, depending on what it is.
  16.  
  17. I read a reference to this technique in Scott Meyer's More Effective C++
  18. but I haven't received my copy yet.  (It is back-ordered at Computer
  19. Literacy).
  20.  
  21. I need someone to basically outline what I need to do to set
  22. up such a function that reads from a stream, produces the appropriate
  23. object and returns a pointer to Packet pointing to the object
  24. which is of the appropriate derived class.
  25.  
  26. At present, I'm trying to implement it as an array of pointers
  27. to functions.  Those functions will be called based on the
  28. Packet type, and create the appropriate object.  Of course I
  29. haven't even thought about going out of scope, destructors,
  30. or such.  My coworker says to just use a big switch statement
  31. and construct objects based on the type.  
  32.  
  33. Any ideas?
  34.  
  35. Thanks in advance,
  36. Clare
  37. clare@shell.portal.com
  38.  
  39.  
  40.  
  41.